package bancosys.tec.rtm.exception;

import org.hibernate.validator.InvalidStateException;
import org.hibernate.validator.InvalidValue;

/**
 * Wraps a {@link InvalidStateException} puting info about all the {@ link InvalidValue} into the exception message text. 
 * 
 * @author seiti
 * Mar 19, 2012
 */
public class ContextualizedInvalidStateException extends Exception {

    private final String message;
    
    /**
     * Ctor
     * 
     * @param invalidStateException invalidStateException  
     */
    public ContextualizedInvalidStateException(InvalidStateException invalidStateException) {
        super(invalidStateException);
        
        StringBuilder invalidValues = new StringBuilder();
        invalidValues.append(invalidStateException.getMessage() + "\n");
        
        for(InvalidValue v : invalidStateException.getInvalidValues()) {
            invalidValues.append(v.getBeanClass() + ": " +  v.getPropertyPath() + v.getMessage() + "\n");
        }
        
        this.message = invalidValues.toString(); 
    }
    
    /**
     * @return a messsage 
     */
    public String getMessage() {
        return this.message;
    }
}
